In the last couple of videos we have learned how to transform a sequence for example a panda series
or a list containing strings with the date time information into a date time index.
So let's import pandas and let's assume that here we have a list with two strings.
So the 20th of May to 15 and the 20th of February to 15 and we can pass here the list to the pandas
method to date time and by doing so we are getting here a day time index with two timestamps.
Now let's assume that we want to create a daytime index service many time stamps.
So for example if we want to f all 31 days in July to 15 so creating and passing all 31 strings to the
two day time method many earlier is actually not really efficient.
And if we have constant frequency so constant increments between the time stamps then we can simply
do this limit the direct Panda's method date range and in our example so all days in July to and fulfills
them the condition.
So we have here a daily frequency or increments of one day.
So let's use here the direct pandas method date range and let's have a look here.
So we have here the stop parameter and two we can pass the string with the date that we want to have
a start.
So here are the first of July and we have also the repair meter end and here we pass the thirty first
off July.
And then there's the additional parameter freq for frequency.
And let's have a look here and here.
The default setting is capital D.
So this stands for days.
So we can also explicitly set the frequency power meter.
Two days this is just here for clarification and by doing so we're actually creating all days starting
from the 1st of July onto the thirty first of July.
So let's do this here and here again see we get to the first or the second the third onto the thirty
first.
And this is set a day time index with uh thirty one time stamps and the data types the date time 64
data type and we have a frequency of D or so daily frequency and let's again have a look here at the
documentation and that the pair meet us.
So essentially we have three parameters we have the stock power meter.
We have for the Empire meter and we have the periods power meter.
And actually we have to define two out of these three parameters to call our date range method.
And of course we have also to define the frequency so instead of passing the first two stop and the
30 first to end B can also pass here the first to start and we can say we want to f thirty one periods
and we want to have a daily frequency.
And by doing so we are getting actually the same identical daytime index from the 1st of July onto the
thirty first of July and s also a third alternative.
So we could alternatively set here the end power meter and the periods pair meter so the end date is
uh the thirty first of July and you want to f 31 periods.
And again the frequency is daily.
And also here we get the same identical daytime index so again we have three paramedics we have stop
and and periods and we have to set are determined to out of these three parameters and additionally
the frequency parameter and for the frequency parameter.
We have many different options so feel free to have a look at the documentation to see all options and
one option is to pass a B for business day.
So again we have here the first of July a start and the thirty first up to my ass end and the U.S.A
business days
and we get the first the second the third and the sixth of July.
So we do not have the fourth and the fifth because of this Saturday and Sunday.
So Saturday and Sunday are not business days and therefore here in this day time index we have only
business days or actually weekdays.
So from Monday to Friday.
All right.
Now let's assume that our start date is the thirty first of July.
And you want to have 10 timestamps with hourly frequency so we pass your h for hourly frequency
and by default we are starting here at midnight on the thirty first of July.
And then we have four year increments of one hour or so we have 1:00 2:00 3:00 until 9:00.
So in total 10 timestamps because they pass the 10 to the parameter periods.
So we have a daytime index that's 10 times stamps and the frequency is h for hourly.
All right and we can also have a weekly frequency.
So yeah our start date as the first of July.
And we want to have six periods and you want to have weekly frequency so we pass yet w to the frequency
parameter
and now at a very first glance this looks quite strange.
So our very first timestamp as of the 5th of July and not to the first of July and this is because by
default if you pass your weekly clear then we get here only some days and actually penned us checks
here from the Stop day bad the very first Sunday is and the very first Sunday is on the 5th.
So here the 5th is our first time stamp.
Then we have our second time stamp at the tomatoes and so on and the very last time stamp and the sixth
time stamp is the 9th of August.
So here we have a daytime index with six some days and we can see this here at the frequency we have
here weekly Sunday and now let's assume that you want to have a starting from the 1st of July it only
Wednesday.
So we want to have the next six best days and we can do this by not passing the weekly but we clear
then minus or dash.
And then Wednesday
and apparently the 1st of July is a Wednesday.
So pandas starts from here.
The starting point and then searches for the very first the Wednesday here in this case it is the 1st
of July.
And then here in total we have the next six Wednesdays from the 1st of July here.
And actually we can create you all week day so we can pass here.
If our AI for Friday are we weekend pass Tuesday and so on and here and the frequency we can see here
that.
Here we have Wednesdays.
All right so now let's go to monthly frequency and for monthly we can pass here.
M So our starting day is the 14th of July and we want to have six timestamps.
So let's try this out here.
And by default when we are passing the M to the frequency parameter we are getting it actually the month
and dates.
So pen that starts here at the 14th of July.
And searches are the very first month and the date and this is the thirty first of July.
And then we have the next consecutive five month ends.
So we have for the thirty first of August the 30th of September and so on.
And let's assume that instead of having the month and we want to for the very first day of each month
and we can do this by passing here m s so far start.
So we get the start of each month and again your partner starts here at the starting point and searches
for the very first uh beginning of months.
And this is here the first of August and then we FBA the first of September and so on and here we can
see the frequency as the month start.
All right.
Now let's assume that we want to have the 14th of July August September October November and December.
So we want to have six period starting from the 14th of July.
And instead of passing your monthly or month start we can pass here a special pants method called Date
offset and tier but then the brackets have to define that the frequency should be month slow the frequency
is one month.
So let's try this out here.
And by doing so we're creating the timestamps 14th of July 14th of August and so on and we can see in
the frequency that we have a date offset of month equals 1.
All right so now let's head to quarterly frequency.
And again our starting point this the 14th of July.
And we want to have a quarterly frequency for six periods.
And if we get us a very first time step the Saudis offer September and typically a quarter is defined
as the first quarter from January to March.
Then the second quarter from April to June then the third quarter from July to September and the fourth
quarter from October to December.
And by default if you pass me a cure then we get to the end date of the quarter.
So the next end date of a quarter is here starting from the 14th of July the 30th of September.
So this is the very last day of the third quarter.
And then the next time stems that consequently the thirty first of December to 15 and then the thirty
first of March to 16 and so on and we can also see this year and the frequency.
So if we pass cure then by default we are getting here.
Q December so that means that the last month of the fourth quarter is December and bypassing here.
Q S instead of Q We are getting actually the very first day off a quarter.
So let's do this here and starting from the 14th of July the very first day of the next quarter is in
the first of October.
Then we get the first of January to 16 and so on.
And in this case the frequency is called Q S January and now let's assume that we want to have quarters
different from January to March April to June and so on.
So let's assume for example that we want to have quarters from May to August and from September to November
and we can do this by passing your flight sample.
Q May and by default we are getting at the very last day of each quarter.
So starting from the 14th of July the next last day of the quarter is the thirty first of August and
so on.
And also instead of getting the last day of each quarter we can get to the first day of each quarter
by passing q s main and we should get then the first of August s first time.
And this is true.
All right now let's go to any other frequency and we are starting here also with the 14th of July.
We want to have six periods and a annual frequency so we can pass here a while we can also pass your
base.
So this is the same
and by default we are getting near the very last day of the calendar year.
So here are the thirty first of December so we are getting here the thirty first of December off to
15 16 17 18 19 and 20.
And the frequency is called annually December and alternative we can also get the very first day of
a calendar year.
So the 1st of January.
And therefore we have to pass a s
and starting from the 14th of July.
So the very first time stem is the first of January to a 16.
And here we can see the frequency as a s.
January All right now let's assume that we want to have annual data but instead of having a year from
January to December we want to f a year from July to June.
And therefore we can pass here a June
A.B. get by default.
The very last day of our year and the very last day is here the 30th of June.
And starting from the 14th of July to 15 our first time stamp is now in 216.
And of course we can also get the very first day of each year by passing year A S June.
And if you want to have the year from July 2 to 1 with the very first day of the year then we have to
pass you a s.
July.
So this should work.
So now we have the 1st of July.
And last but not least we can also create a yearly timestamps for example for the 24th of November.
So this is my birthday.
And let's assume I want to f the time stamps for the last 10 birthdays.
So the last birthday was on the 24th of November to 18 and periods is 10.
And here again I can pass the special method BD Date date offset to the frequency prior meter.
And you're within the brackets like I can pass the frequency of one year.
So let's try this out until we get to the day time index with the last 10 best days.
So starting from the 24th of November 2009 to the 24th of November 2018.
All right.
This was a very detailed look on the date range method and are actually plenty of combinations that
we can use here.
So the date range method is quite powerful and useful.
And in practice there's hardly any case that we cannot come up with the date range method.
So this is very useful and with this we are finished with this video and I hope to see you also in the
next one by.